diff --git a/library/NGNPro/Records/SipAccounts.php b/library/NGNPro/Records/SipAccounts.php index e04471d..f83b718 100644 --- a/library/NGNPro/Records/SipAccounts.php +++ b/library/NGNPro/Records/SipAccounts.php @@ -1,1278 +1,1300 @@ 'Change date', - 'username' => 'Username', - 'domain' => 'Domain' - ); + var $sortElements = array( + 'changeDate' => 'Change date', + 'username' => 'Username', + 'domain' => 'Domain' + ); - var $store_clear_text_passwords=true; + var $store_clear_text_passwords = true; var $default_account_type = 'postpaid'; - var $group_filter_list = array('blocked' => 'Blocked', - 'quota' => 'Quota Exceeded', - 'prepaid' => 'Prepaid', - 'free-pstn' => 'PSTN Access', - 'anonymous' => 'Anonymous', - 'anonymous-reject' => 'Reject Anonymous', - 'voicemail' => 'Has Voicemail', - 'missed-calls' => 'Missed Calls', - 'trunking' => 'Trunking' - ); + var $group_filter_list = array( + 'blocked' => 'Blocked', + 'quota' => 'Quota Exceeded', + 'prepaid' => 'Prepaid', + 'free-pstn' => 'PSTN Access', + 'anonymous' => 'Anonymous', + 'anonymous-reject' => 'Reject Anonymous', + 'voicemail' => 'Has Voicemail', + 'missed-calls' => 'Missed Calls', + 'trunking' => 'Trunking' + ); public function __construct($SoapEngine) { dprint("init SipAccounts"); - $this->filters = array('username' => strtolower(trim($_REQUEST['username_filter'])), - 'domain' => strtolower(trim($_REQUEST['domain_filter'])), - 'firstname'=> trim($_REQUEST['firstname_filter']), - 'lastname' => trim($_REQUEST['lastname_filter']), - 'email' => htmlspecialchars(trim($_REQUEST['email_filter'])), - 'owner' => trim($_REQUEST['owner_filter']), - 'customer' => trim($_REQUEST['customer_filter']), - 'reseller' => trim($_REQUEST['reseller_filter']), - 'group' => trim($_REQUEST['group_filter']) + $this->filters = array( + 'username' => strtolower(trim($_REQUEST['username_filter'])), + 'domain' => strtolower(trim($_REQUEST['domain_filter'])), + 'firstname'=> trim($_REQUEST['firstname_filter']), + 'lastname' => trim($_REQUEST['lastname_filter']), + 'email' => htmlspecialchars(trim($_REQUEST['email_filter'])), + 'owner' => trim($_REQUEST['owner_filter']), + 'customer' => trim($_REQUEST['customer_filter']), + 'reseller' => trim($_REQUEST['reseller_filter']), + 'group' => trim($_REQUEST['group_filter']) ); parent::__construct($SoapEngine); if (strlen($this->SoapEngine->call_limit)) { $this->platform_call_limit = $this->SoapEngine->call_limit; } else { $this->platform_call_limit; } $this->getTimezones(); } - function getRecordKeys() { - - if (preg_match("/^(.*)@(.*)$/",$this->filters['username'], $m)) { + function getRecordKeys() + { + if (preg_match("/^(.*)@(.*)$/", $this->filters['username'], $m)) { $this->filters['username'] = $m[1]; $this->filters['domain'] = $m[2]; } // Filter - $filter=array('username' => $this->filters['username'], - 'domain' => $this->filters['domain'], - 'firstName'=> $this->filters['firstname'], - 'lastName' => $this->filters['lastname'], - 'email' => $this->filters['email'], - 'owner' => intval($this->filters['owner']), - 'customer' => intval($this->filters['customer']), - 'reseller' => intval($this->filters['reseller']), - 'groups' => array($this->filters['group']) - ); + $filter = array( + 'username' => $this->filters['username'], + 'domain' => $this->filters['domain'], + 'firstName'=> $this->filters['firstname'], + 'lastName' => $this->filters['lastname'], + 'email' => $this->filters['email'], + 'owner' => intval($this->filters['owner']), + 'customer' => intval($this->filters['customer']), + 'reseller' => intval($this->filters['reseller']), + 'groups' => array($this->filters['group']) + ); // Range - $range=array('start' => 0, - 'count' => 500 - ); + $range = array( + 'start' => 0, + 'count' => 500 + ); // Order if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'changeDate'; if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'DESC'; - $orderBy = array('attribute' => $this->sorting['sortBy'], - 'direction' => $this->sorting['sortOrder'] - ); + $orderBy = array( + 'attribute' => $this->sorting['sortBy'], + 'direction' => $this->sorting['sortOrder'] + ); // Compose query - $Query=array( + $Query = array( 'filter' => $filter, 'orderBy' => $orderBy, 'range' => $range ); // Insert credetials $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getAccounts'); // Call function $result = $this->SoapEngine->soapclient->getAccounts($Query); if ((new PEAR)->isError($result)) { $error_msg = $result->getMessage(); $error_fault= $result->getFault(); $error_code = $result->getCode(); - $log=sprintf("SOAP request error from %s: %s (%s): %s",$this->SoapEngine->SOAPurl, $error_msg, $error_fault->detail->exception->errorcode, $error_fault->detail->exception->errorstring); + $log = sprintf("SOAP request error from %s: %s (%s): %s",$this->SoapEngine->SOAPurl, $error_msg, $error_fault->detail->exception->errorcode, $error_fault->detail->exception->errorstring); syslog(LOG_NOTICE, $log); return false; } else { foreach ($result->accounts as $account) { - $this->selectionKeys[]=array('username' => $account->id->username, - 'domain' => $account->id->domain - ); + $this->selectionKeys[] = array( + 'username' => $account->id->username, + 'domain' => $account->id->domain + ); } return true; } return false; } function listRecords() { $this->getAllowedDomains(); - if (preg_match("/^(.*)@(.*)$/",$this->filters['username'], $m)) { + if (preg_match("/^(.*)@(.*)$/", $this->filters['username'], $m)) { $this->filters['username'] = $m[1]; $this->filters['domain'] = $m[2]; } $this->showSeachForm(); // Filter - $filter=array('username' => $this->filters['username'], - 'domain' => $this->filters['domain'], - 'firstName'=> $this->filters['firstname'], - 'lastName' => $this->filters['lastname'], - 'email' => $this->filters['email'], - 'owner' => intval($this->filters['owner']), - 'customer' => intval($this->filters['customer']), - 'reseller' => intval($this->filters['reseller']), - 'groups' => array($this->filters['group']) - ); + $filter = array( + 'username' => $this->filters['username'], + 'domain' => $this->filters['domain'], + 'firstName'=> $this->filters['firstname'], + 'lastName' => $this->filters['lastname'], + 'email' => $this->filters['email'], + 'owner' => intval($this->filters['owner']), + 'customer' => intval($this->filters['customer']), + 'reseller' => intval($this->filters['reseller']), + 'groups' => array($this->filters['group']) + ); $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; + // Range - $range=array('start' => intval($this->next), - 'count' => intval($this->maxrowsperpage) - ); + $range = array( + 'start' => intval($this->next), + 'count' => intval($this->maxrowsperpage) + ); // Order if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'changeDate'; if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'DESC'; - $orderBy = array('attribute' => $this->sorting['sortBy'], - 'direction' => $this->sorting['sortOrder'] - ); + $orderBy = array( + 'attribute' => $this->sorting['sortBy'], + 'direction' => $this->sorting['sortOrder'] + ); // Compose query - $Query=array('filter' => $filter, - 'orderBy' => $orderBy, - 'range' => $range - ); + $Query = array( + 'filter' => $filter, + 'orderBy' => $orderBy, + 'range' => $range + ); // Insert credentials $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getAccounts'); // Call function - $result = $this->SoapEngine->soapclient->getAccounts($Query); + $result = $this->SoapEngine->soapclient->getAccounts($Query); if ((new PEAR)->isError($result)) { $error_msg = $result->getMessage(); $error_fault= $result->getFault(); $error_code = $result->getCode(); - $log=sprintf("SOAP request error from %s: %s (%s): %s",$this->SoapEngine->SOAPurl, $error_msg, $error_fault->detail->exception->errorcode, $error_fault->detail->exception->errorstring); + $log = sprintf("SOAP request error from %s: %s (%s): %s",$this->SoapEngine->SOAPurl, $error_msg, $error_fault->detail->exception->errorcode, $error_fault->detail->exception->errorstring); syslog(LOG_NOTICE, $log); return false; } else { $this->rows = $result->total; if ($this->rows && $action != 'PerformActions' && $action != 'Delete') { $this->showActionsForm(); } print "

$this->rows records found

"; if (!$this->next) $this->next=0; - if ($this->rows > $this->maxrowsperpage) { + if ($this->rows > $this->maxrowsperpage) { $maxrows = $this->maxrowsperpage + $this->next; if ($maxrows > $this->rows) $maxrows = $this->maxrowsperpage; } else { - $maxrows=$this->rows; + $maxrows = $this->rows; } if ($this->rows) { $i=0; - $_prepaid_accounts=array(); - while ($i < $maxrows) { + $_prepaid_accounts = array(); + while ($i < $maxrows) { if (!$result->accounts[$i]) break; $account = $result->accounts[$i]; if ($account->prepaid) { - $_prepaid_accounts[]=array("username" => $account->id->username, - "domain" => $account->id->domain - ); + $_prepaid_accounts[] = array( + "username" => $account->id->username, + "domain" => $account->id->domain + ); } $i++; } if (count($_prepaid_accounts)) { // Insert credetials $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getPrepaidStatus'); // Call function - $result1 = $this->SoapEngine->soapclient->getPrepaidStatus($_prepaid_accounts); + $result1 = $this->SoapEngine->soapclient->getPrepaidStatus($_prepaid_accounts); if (!(new PEAR)->isError($result1)) { $j=0; foreach ($result1 as $_account) { - $_sip_account=sprintf("%s@%s",$_prepaid_accounts[$j]['username'], $_prepaid_accounts[$j]['domain']); - $_prepaid_balance[$_sip_account]=$_account->balance; + $_sip_account = sprintf( + "%s@%s", + $_prepaid_accounts[$j]['username'], + $_prepaid_accounts[$j]['domain'] + ); + $_prepaid_balance[$_sip_account] = $_account->balance; $j++; } } } $i=0; while ($i < $maxrows) { if (!$result->accounts[$i]) break; $account = $result->accounts[$i]; - $index=$this->next+$i+1; + $index = $this->next+$i+1; $deleteUrl = array( 'service' => $this->SoapEngine->service, 'action' => 'Delete', 'key' => $account->id->username ); if (!$this->filters['domain']) { $deleteUrl['domain_filter'] = $account->id->domain; } if (!$this->filters['username']) { $deleteUrl['username_filter'] = $account->id->username; } if ($action == 'Delete' && $_REQUEST['key'] == $account->id->username && $_REQUEST['domain_filter'] == $account->id->domain) { $deleteUrl['confirm'] = 1; $actionText = "Confirm"; } else { $actionText = "Delete"; } if ($account->reseller) { - $reseller_sip_settings_page=$account->reseller; + $reseller_sip_settings_page = $account->reseller; } else if ($this->SoapEngine->impersonate) { // use the reseller from the soap engine - $reseller_sip_settings_page=$this->SoapEngine->impersonate; + $reseller_sip_settings_page = $this->SoapEngine->impersonate; } else { // use the reseller from the login - $reseller_sip_settings_page=$this->reseller; + $reseller_sip_settings_page = $this->reseller; } if ($this->sip_settings_page) { $settingsUrl = array( 'account' => sprintf('%s@%s', $account->id->username, $account->id->domain), 'sip_engine' => $this->SoapEngine->sip_engine ); if ($this->adminonly) { $settingsUrl['reseller'] = $reseller_sip_settings_page; $settingsUrl['adminonly'] = $this->adminonly; } else { if ($account->reseller == $this->reseller) $settingsUrl['reseller'] = $reseller_sip_settings_page; } foreach (array_keys($this->SoapEngine->extraFormElements) as $element) { if (!strlen($this->SoapEngine->extraFormElements[$element])) continue; $settingsUrl[$element] = $this->SoapEngine->extraFormElements[$element]; } $sip_account = sprintf( " %s@%s", $this->sip_settings_page, http_build_query($settingsUrl), $account->id->username, $account->id->domain ); } else { - $sip_account = sprintf("%s@%s",$account->id->username, $account->id->domain); + $sip_account = sprintf("%s@%s", $account->id->username, $account->id->domain); } /* $_customer_url = $this->url.sprintf("&service=customers@%s&customer_filter=%s", urlencode($this->SoapEngine->customer_engine), urlencode($account->customer)); */ if ($account->owner) { $ownersUrlData = array( 'service' => sprintf('customers@%s', $this->SoapEngine->soapEngine), 'customer_filter' => $account->owner ); $_owner_url = sprintf( '%s', $this->url, http_build_query($ownersUrlData), $account->owner ); } else { $_owner_url=''; } $prepaid_account = sprintf("%s@%s", $account->id->username, $account->id->domain); if ($account->callLimit) { $callLimit = $account->callLimit; - } else if ($this->platform_call_limit) { + } elseif ($this->platform_call_limit) { $callLimit = $this->platform_call_limit; } else { $callLimit = ''; } printf( ' ', $index, $sip_account, $account->firstName, $account->lastName, $account->email, $account->email, $account->timezone, $callLimit, $account->quota, $_prepaid_balance[$prepaid_account], $_owner_url, $account->changeDate, $this->url.'&'.$this->addFiltersToURL().'&'.http_build_query($deleteUrl), $actionText ); $i++; } } print "
Id SIP account"; $this->showSortCaret('username'); - if ($this->sorting['sortBy'] == 'domain' ) { + if ($this->sorting['sortBy'] == 'domain') { print " (domain "; $this->showSortCaret('domain'); print ")"; } print " Full name Email address Timezone Capacity Quota Balance Owner Change date"; $this->showSortCaret('changeDate'); print " Actions
%s %s %s %s %s %s %s %s %s %s %s %s
"; $this->showPagination($maxrows); return true; } } function showSeachFormCustom() { - printf (" -

Account
",$this->filters['username']); - printf ("@"); + printf( + "
Account
", + $this->filters['username'] + ); + print "@"; if (count($this->allowedDomains) > 0) { if ($this->filters['domain'] && !in_array($this->filters['domain'], $this->allowedDomains)) { - printf ("",$this->filters['domain']); + printf("", $this->filters['domain']); } else { $selected_domain[$this->filters['domain']]='selected'; - printf ("